home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93b.txt / 000052_icon-group-sender _Wed Apr 28 13:10:24 1993.msg < prev    next >
Internet Message Format  |  1993-06-16  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Mon, 3 May 1993 05:25:45 MST
  2. Date: 28 Apr 93 13:10:24 GMT
  3. From: mercury.hsi.com!mlfarm!cs.arizona.edu!icon-group@uunet.uu.net  (Jerry D. Nowlin)
  4. Subject: Re: Help!
  5. Message-Id: <9304281310.AA23936@iwtqg>
  6. Sender: icon-group-request@cs.arizona.edu
  7. To: icon-group@cs.arizona.edu
  8. Status: R
  9. Errors-To: icon-group-errors@cs.arizona.edu
  10.  
  11.  
  12.  > erholm@CS.ColoState.EDU (scott erholm) writes:
  13.  >
  14.  > In Pascal, I could pass values to and from procedures in this manner:
  15.  >
  16.  > Procedure P (VAR x, y, z : Integer; l, m : Real);
  17.  >    (* procedure body *)
  18.  > end;
  19.  >
  20.  > And the call to P would look like this:
  21.  >
  22.  > P (a, b, c, 10, 20);
  23.  >
  24.  > meaning that procedure P would get 10 and 20 for l and m, and would
  25.  > pass the values of x, y, and z back to the calling program.
  26.  
  27. In Icon you can pass a list into a procedure and then stuff things into it
  28. or yank things out of it and when the procedure exits the list remains
  29. modified.  If you pass an empty list to a procedure you can put the x, y
  30. and z values in it and access them from the calling routine.  An empty
  31. table may be more convenient if you want to access the values returned in a
  32. specific order.
  33.  
  34. Finally, while an Icon procedure can only return one item, that item can be
  35. a list or table or any other Icon type.  Rather than including an empty
  36. list or table in the parameter list why not just return one you constructed
  37. on the fly inside the procedure.  Icon magically keeps the values in the
  38. list or table around for you until you don't need them anymore.  Oh sure...
  39. you could explain it in terms of pointers and that other technical stuff
  40. but I like magic.
  41.  
  42.     procedure main()
  43.         addem(l := [],t := table())
  44.         every write(!l | t[1 to 3] | !retem())
  45.     end
  46.  
  47.     procedure addem(l,t)
  48.         every put(l,"new"|"list"|"items")
  49.         t[1] := "and"
  50.         t[2] := "table"
  51.         t[3] := "values"
  52.     end
  53.  
  54.     procedure retem()
  55.         every put(l := [],"and"|"more"|"list"|"items")
  56.         return l
  57.     end
  58.  
  59. Jerry Nowlin
  60. nowlin@iwtqg.att.com (work)
  61. isidev!nowlin@uunet.uu.net (home)
  62.